﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Markup;

namespace CoreModule.Converters
{
    /// <summary>
    /// 
    /// </summary>
    /// 
    [ContentProperty("Values")]
    public class StringPlaceholderConverter : IValueConverter
    {
        private List<string> _values = new List<string>();
        public IList Values => _values;
        public bool IsNullOrEmpty { get; set; } = true;
        public bool IsNullOrWhiteSpace { get; set; } = true;
        public string Placeholder { get; set; } = "-";
         
        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (IsNullOrEmpty && string.IsNullOrEmpty(value?.ToString()))
            {
                return Placeholder;
            }
            if (IsNullOrWhiteSpace && string.IsNullOrWhiteSpace(value?.ToString()))
            {
                return Placeholder;
            }

            if (Values.Count>0 && Values.Contains(value))
            {
                return Placeholder;
            }

            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
